package edu.wit.common.web;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import edu.wit.common.exception.ResultEnums;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageResult<T> implements Serializable{

	private static final long serialVersionUID = 3200755507469394010L;

	/**
	 * 总条数
	 */
    @JsonView(GeneralViews.normalView.class)
	private int count;
    @JsonView(GeneralViews.normalView.class)
	private int code;
    @JsonView(GeneralViews.normalView.class)
	private List<T> data;
    @JsonView(GeneralViews.normalView.class)
	private Date nowTime;
	/**
	 * 当前页
	 */
	@JsonIgnore
	private Integer current;
    @JsonIgnore
	private Integer size;

	public PageResult(Long count, int code, List<T> data, Date nowTime) {
		super();
		this.count = count.intValue();
		this.code = code;
		this.data = data;
		this.nowTime = nowTime;
	}

    /**
     * @param data	数据
     * @param count	总条数
     * @return
     */
    public static <T> PageResult<T> success(List<T> data, Long count) {
//        return new PageResult<T>(count, ResultEnums.SUCCESS.getCode(), data, new Date());
		return new PageResult<T>(count, ResultEnums.SUCCESS.getCode(), data, new Date());

	}

	/**
	 * @param data		数据
	 * @param count		总条数
	 * @param current	当前页
	 * @param size		每页数量
	 * @return
	 */
	public static <T> PageResult<T> success(List<T> data, Long count,Integer current,Integer size) {
//        return new PageResult<T>(count, ResultEnums.SUCCESS.getCode(), data, current, size, new Date());
		return new PageResult<T>(count, ResultEnums.SUCCESS.getCode(), data, current, size, new Date());
    }

	public PageResult(Long count, Integer code, List<T> data, Integer current, Integer size, Date date) {
		super();
		this.count = count.intValue();
		this.code = code;
		this.data = data;
		this.current = current;
		this.size = size;
		this.nowTime = date;
	}

}
